package com.hxkj.controller;

import com.hxkj.domain.po.AuthFunction;
import com.hxkj.domain.po.FunctionTree;
import com.hxkj.service.FunctionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * @author Mrmas
 * @create 2018-05-24 14:08
 * @desc 功能列表前置服务
 **/
@RestController
@RequestMapping("/function")
public class FunctionController {

    @Autowired
    private FunctionService functionService;


    /**
     * 获取功能树
     *
     * @throws Exception
     */
    @RequiresPermissions("function:view")
    @RequestMapping(value = "/getlist")
    public Callable<List<FunctionTree>> getFunctions(@ModelAttribute AuthFunction authFunction) throws Exception {
        return () -> functionService.getFunctions(authFunction);
    }


    /**
     * 增加功能
     *
     * @throws Exception
     */
    @RequiresPermissions("function:add")
    @RequestMapping(value = "/save")
    public void saveFunction(@ModelAttribute AuthFunction authFunction) throws Exception {
        functionService.saveFunction(authFunction);
    }


    /**
     * 更新功能
     *
     * @throws Exception
     */
    @RequiresPermissions("function:modify")
    @RequestMapping(value = "/modify")
    public void updateFunction(@ModelAttribute AuthFunction authFunction) throws Exception {
        functionService.updateFunction(authFunction);
    }


    /**
     * 删除功能
     *
     * @throws Exception
     */
    @RequiresPermissions("function:remove")
    @RequestMapping(value = "/remove")
    public void deleteFunction(@ModelAttribute AuthFunction authFunction) throws Exception {
        functionService.deleteFunction(authFunction);
    }


    /**
     * 查询单个功能
     *
     * @throws Exception
     */
    @RequiresPermissions("function:view")
    @RequestMapping(value = "/get")
    public Object queryAuthFunction(@ModelAttribute AuthFunction authFunction) throws Exception {
        return functionService.queryAuthFunction(authFunction);
    }


    /**
     * 更新orderId
     *
     * @throws Exception
     */
    @RequiresPermissions("function:modify")
    @RequestMapping(value = "/modifyOrderIds")
    public void modifyOrderIds(@RequestParam HashMap<String, Object> map) throws Exception {
        functionService.modifyOrderIds(map);
    }
}
